function updateDate(typeName,fromName,toName){
  var today = new Date();
  var ty = document.getElementById(typeName).value;
  var ds=[];
    switch(ty){
		case '': 
		    ds[0]='';
			ds[1]='';
			break;    
		case 'today': 
		    ds[0]=today.parseString();
			ds[1]=today.parseString();
			break;
		case 'theWeek': 
            ds=today.theWeek();
			break;
		case 'lastWeek':
		    ds=today.lastWeek();
			break;
		case 'theMonth':
            ds=today.theMonth();
			break;
		case 'lastMonth':
            ds=today.lastMonth();
			break;
		case 'theQuarter':
			ds=today.theQuarter();
			break;
		case 'lastQuarter':
			ds=today.lastQuarter();
			break;
		case 'theYear':
			ds=today.theYear();
			break;
		case 'lastYear':
			ds=today.lastYear();
			break;
		case 'last7Day':
			ds=today.lastDays(7);
			break;
		case 'last30Day':
			ds=today.lastDays(30);
			break;
		case 'custom':
		    ds[0]='';
			ds[1]='';
			break;			
    }
　　 if (ds!=null){
    document.getElementById(fromName).value=ds[0];
	document.getElementById(toName).value=ds[1];
	}
}

function updateType(typeName){
    document.getElementById(typeName).selectedIndex=12;
}

//返回该月天数
Date.prototype.getDaysOfMonth = function (){
	return (new Date(this.getFullYear(),this.getMonth()+1,0)).getDate();
}

//上个季度
Date.prototype.lastQuarter = function(){
    var arr= [];
　　var m = this.getMonth();
    var q = Math.floor(m/3)+1;//本季度
    
	var f;//开始
	var l;//结束
    switch(q){
		case 1: 
			f=new Date(this.getFullYear()-1,9,1);
            l=new Date(this.getFullYear()-1,11,31);
			break;
		case 2: 
			f=new Date(this.getFullYear(),0,1);
            l=new Date(this.getFullYear(),2,31);
			break;
		case 3: 
			f=new Date(this.getFullYear(),3,1);
            l=new Date(this.getFullYear(),5,30);
			break;
		case 4: 
			f=new Date(this.getFullYear(),6,1);
            l=new Date(this.getFullYear(),8,30);
			break;
	}

    arr[0]=f.parseString();	
    arr[1]=l.parseString();
	return arr;
}
//本季度
Date.prototype.theQuarter = function(){
    var arr= [];
　　var m = this.getMonth();
    var q = Math.floor(m/3)+1;//季度
    
	var t=new Date(this.getFullYear(),3*q-2-1,1);
    arr[0]=t.parseString();	
    arr[1]=this.parseString();
	return arr;
}



//去年
Date.prototype.lastYear = function(){
    var arr= [];
	var t = new Date(this.getFullYear()-1,0,1);//去年
    var l= new Date(this.getFullYear()-1,11,31);//去年

    arr[0]=t.parseString();	
    arr[1]=l.parseString();  
	return arr;
}

//今年
Date.prototype.theYear = function(){
    var arr= [];
	var t = new Date(this.getFullYear(),0,1);
    arr[0]=t.parseString();	
    arr[1]=this.parseString(); 
	return arr;
}
//最近几天
Date.prototype.lastDays = function(num){
    var arr= [];
    arr[0]=this.dateAfter(-num).parseString();	
    arr[1]=this.parseString();
	return arr;
}

//上月
Date.prototype.lastMonth = function(){
    var arr= [];
	var t = new Date(this.getFullYear(),this.getMonth(),1);//本月第一天
    var l= t.dateAfter(-1);//上月最后一天
    var f = new Date(l.getFullYear(),l.getMonth(),1);//上月第一天

    arr[0]=f.parseString();	
    arr[1]=l.parseString(); //上月最后一天
	return arr;
}


//本月
Date.prototype.theMonth = function(){
    var arr= [];
	var d=this.getDate();
    arr[0]=this.dateAfter(-d+1).parseString();
    arr[1]=this.parseString();
	return arr;
}

//本周
Date.prototype.theWeek = function(){
    var arr= [];
	var w=this.getDay();
    if (w==0) w=7;
    arr[0]=this.dateAfter(-w).parseString();
    arr[1]=this.parseString();
	return arr;
}

//上周
Date.prototype.lastWeek = function(){
    var arr= [];
	var w=this.getDay();
    if (w==0) w=7;
    arr[0]=this.dateAfter(-w-7).parseString();
    arr[1]=this.dateAfter(-w).parseString();
	return arr;
}

/*将一位数字格式化成两位,如: 9 to 09*/
String.prototype.fmtWithZero = function(isFmtWithZero){
if(isFmtWithZero)
return (this<10?"0"+this:this);
else return this;
}
String.prototype.fmtWithZeroD = function(isFmtWithZero){
if(isFmtWithZero)
return (this<10?"00"+this:(this<100?"0"+this:this));
else return this;
}
/*
* 功能:根据输入表达式返回日期字符串
* 参数:dateFmt:字符串,由以下结构组成 
* yy:长写年,YY:短写年mm:数字月,MM:英文月,dd:日,hh:时,
* mi:分,ss秒,ms:毫秒,we:汉字星期,WE:英文星期.
* isFmtWithZero : 是否用0进行格式化,true or false
*/
Date.prototype.parseString = function(dateFmt,isFmtWithZero){
dateFmt = (dateFmt == null?"yy-mm-dd" : dateFmt);
isFmtWithZero = (isFmtWithZero == null?true : isFmtWithZero);
if(typeof(dateFmt) != "string" )
throw (new Error(-1, 'parseString()方法需要字符串类型参数!'));
var weekArr=[["星期日","星期一","星期二","星期三","星期四","星期五","星期六"],
["SUN","MON","TUR","WED","THU","FRI","SAT"]];
var monthArr=["JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC"];
var str=dateFmt;
str = str.replace(/yy/g,this.getFullYear());
str = str.replace(/YY/g,this.getYear());
str = str.replace(/mm/g,(this.getMonth()+1).toString().fmtWithZero(isFmtWithZero));
str = str.replace(/MM/g,monthArr[this.getMonth()]);
str = str.replace(/dd/g,this.getDate().toString().fmtWithZero(isFmtWithZero));
str = str.replace(/hh/g,this.getHours().toString().fmtWithZero(isFmtWithZero));
str = str.replace(/mi/g,this.getMinutes().toString().fmtWithZero(isFmtWithZero));
str = str.replace(/ss/g,this.getSeconds().toString().fmtWithZero(isFmtWithZero));
str = str.replace(/ms/g,this.getMilliseconds().toString().fmtWithZeroD(isFmtWithZero));
str = str.replace(/we/g,weekArr[0][this.getDay()]);
str = str.replace(/WE/g,weekArr[1][this.getDay()]);
return str;
}

 //格式化成2006-01-01的格式
 Date.prototype.formatString = function(){
   var s='';
   s+=this.getFullYear()+"-"; 
   s +=(this.getMonth()+1)+"-";   
   s+=this.getDate();        
   return s;
 }

 Date.prototype.minusDays = function(days){
     var interTimes = days * 24 * 60 * 60 * 1000 ;
     return new Date(Date.parse(this) - interTimes) ;     
 }

 
/* 功能 : 返回与某日期相距N天(N个24小时)的日期
* 参数 : num number类型 可以为正负整数或者浮点数,默认为1;
* type 0(秒) or 1(天),默认为秒
* 返回 : 新的PowerDate类型
*/
Date.prototype.dateAfter=function(num,type){
num = (num == null?1:num);
if(typeof(num)!="number") throw new Error(-1,"dateAfterDays(num,type)的num参数为数值类型.");
type = (type==null?1:type);
var arr = [1000,86400000];
var dd = this.valueOf();
dd += num*arr[type];
return new Date(dd);
}
